package com.fp.m7.server.helpers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fp.m7.api.model.Account;
import com.fp.m7.shared.dto.AccountDto;
import com.fp.m7.shared.dto.UserDto;

/**
 * Factory for creating accountDto's.
 * 
 * @author 7
 */
@Component
public class AccountDtoFactory {

    @Autowired
    private UserDtoFactory userDtoFactory;

    public AccountDto build(Account account) {
        UserDto userDto = userDtoFactory.build(account);
        return new AccountDto(account.getId(), account.getDescription(), account.getStatus(), userDto);
    }

    public List<AccountDto> build(List<Account> accounts) {
        List<AccountDto> rtrn = new ArrayList<AccountDto>(accounts.size());
        for (Account account : accounts) {
            if (account != null) {
                rtrn.add(build(account));
            }
        }
        return rtrn;
    }

    public void setUserDtoFactory(UserDtoFactory userDtoFactory) {
        this.userDtoFactory = userDtoFactory;
    }
}
